package com.wstx.mediaserver.controller;

import com.wstx.mediaserver.common.Res;
import com.wstx.mediaserver.service.FileService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
public class FileController {

    final FileService fileService;

    @PostMapping("upload")
    public Res<String> upload(
            @RequestParam(value = "fileName", required = false) String fileName,
            @RequestParam("file") MultipartFile file) {
        try {
            String fileUrl = fileService.upload(fileName, file);
            return new Res<String>().suc(fileUrl);
        } catch (Exception e) {
            //todo:待替换语句
            e.printStackTrace();
            return Res.fail(e.getMessage());
        }
    }
}
